from django.contrib.auth.models import AbstractUser
from django.db import models
from django.utils import timezone


# Create your models here.

class UserProfile(AbstractUser):
    name = models.CharField(max_length=100, blank=True, verbose_name='姓名')
    # avatar = models.ImageField(upload_to='avatar/%Y/%m', default='avatar/default.png', max_length=200, blank=True,
    #                            null=True, verbose_name='用户头像')
    birthday = models.DateField(null=True, blank=True, verbose_name='出生年月')
    gender = models.CharField(max_length=6, choices=(('male', '男'), ('female', '女')), default='female',
                              verbose_name='性别')
    phone = models.CharField(max_length=11, null=True, blank=True)
    add_time = models.DateTimeField('创建时间', default=timezone.now, blank=True)
    mod_time = models.DateTimeField('更新时间', auto_now=True, blank=True)
    email = models.CharField(max_length=100, blank=True)

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class VerifyCode(models.Model):
    """
    短信验证码
    """
    code = models.CharField(max_length=10, verbose_name="验证码")
    phone = models.CharField(max_length=11, verbose_name="电话号码")
    add_time = models.DateTimeField(default=timezone.now, verbose_name="添加时间")
    count = models.IntegerField(default=0, verbose_name='统计次数')

    class Meta:
        verbose_name = "短信验证码"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
